package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.page.PageResult;
import com.dongdongshop.service.EsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("es")
public class EsController {
    @DubboReference(check = false,timeout = 5000000)
    private EsService esService;

    @RequestMapping("toEs")
    public String toEs(String title, Model model){
        model.addAttribute("title",title);
        return "search";
    }
    @RequestMapping("getItemList")
    @ResponseBody
    public Result getItemList(String title,
                              @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        try {
            PageResult list =  esService.getItemList(title,pageNum,pageSize);
            return Result.OK().setData(list);
        }catch (Exception e){
            return Result.ERROR();
        }
    }

}
